home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FTELL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  785 b   |  30 lines

  1. /*  ftell.c, from p. 437 of Turbo C Bible  */
  2. #include <stdio.h>
  3. main()
  4. {
  5.     long curpos;
  6.     FILE *infile;
  7.     char filename[80], buffer[80];
  8.     printf("Enter name of a text file: ");
  9.     gets(filename);
  10.                 /*  Open the file for reading  */
  11.     if ((infile = fopen(filename, "rb")) == NULL)
  12.     {
  13.     printf("fopen failed.");
  14.     exit(0);
  15.     }
  16.                 /*  Read 80 character and display the  */
  17.                 /*  buffer                             */
  18.     fread(buffer, sizeof(char), 80, infile);
  19.     printf("read these 80 characters:\n %s\n", buffer);
  20.                 /*  Get and display current position   */
  21.     if ((curpos = ftell(infile)) == -1L)
  22.     {
  23.     perror("ftell failed!");
  24.     }
  25.     else
  26.     {
  27.     printf("Currently at %ld bytes from beginning \
  28.         of file\n", curpos);
  29.     }
  30. }